package com.online.college.common.play;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.exceptions.ClientException;
// 每个API都需要引入对应的类，此处以调用GetVideoPlayAuth接口为例
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;


public class AliPlay {

    public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client, String videoId) {
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(videoId); //视频ID
        GetVideoPlayAuthResponse response = null;
        try {
            response = client.getAcsResponse(request);
        } /*catch (ServerException e) {
            throw new RuntimeException("GetVideoPlayAuthRequest Server failed");
        } */catch (ClientException e) {
            throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
        }
        response.getPlayAuth();              // 播放凭证
        response.getVideoMeta();             // 视频Meta信息
        return response;
    }

    /**
     * 根据视频id获取对应的阿里云视频播放权限
     * @param videoId
     * @return
     */
    public static GetVideoPlayAuthResponse getVideoPlayAuth(String videoId) {
        String accessKeyId = "LTAIUJKhehIjBWZC";
        String accessKeySecret = "lAlX7OI2I0NS0VdeUYnDfAIqwprkFf";
        // 点播服务所在的Region，国内请填cn-shanghai，不要填写别的区域
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        GetVideoPlayAuthResponse resp = getVideoPlayAuth(client,videoId);
        return resp;
    }

    /*public static void main(String[] args) {
        String accessKeyId = "LTAIUJKhehIjBWZC";
        String accessKeySecret = "lAlX7OI2I0NS0VdeUYnDfAIqwprkFf";
        // 点播服务所在的Region，国内请填cn-shanghai，不要填写别的区域
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        GetVideoPlayAuthResponse resp = getVideoPlayAuth(client);
        System.out.println(resp.getPlayAuth());
    }*/
}
